import torch
from transformers import BertModel


pretrained = BertModel.from_pretrained(r"D:\AI\model\bert-base-chinese")

print(pretrained)
# 修改模型position_embeddings
pretrained.embeddings.position_embeddings = torch.nn.Embedding(1500, 768)
# 修改模型 word_embeddings
pretrained.embeddings.word_embeddings = torch.nn.Embedding(21130, 768)

print(pretrained)